<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <button class="get">get</button>
    <button class="post">post</button>
    <button class="ajax_get">ajaxget</button>
    <button class="ajax_post">ajaxpost</button>
    <script>
        $(function () {
            $('.get').on('click', function () {
                $.get('http://www.liulongbin.top:3006/api/getbooks', function (res) {
                    console.log(res);
                })
            });
            // id: 1, bookname: "水浒吧", author: "三三三", publisher: "拜拜图书出版社"
            //addbook
            $('.post').on('click', function () {
                $.post('http://www.liulongbin.top:3006/api/post', { bookname: "水浒吧", author: "三三三", publisher: "拜拜图书出版社" }, function (res) {
                    console.log(res);
                })
            });

            // ajax请求
            $('.ajax_get').on('click', function () {
                $.ajax({
                    type: 'GET',
                    url: 'http://www.liulongbin.top:3006/api/getbooks',
                    data: {},
                    success: function (res) {
                        console.log(res);
                    }
                });
            });

            //ajax请求
            $('.ajax_post').on('click', function () {
                $.ajax({
                    type: "POST",
                    url: 'http://www.liulongbin.top:3006/api/addbook',
                    data: {
                        bookname: "水浒吧",
                        author: "三三三",
                        publisher: "拜拜图书出版社"
                    },
                    success: function (res) {
                        console.log(res);
                    }
                });
            });



        });
    </script>
</body>

</html>